//
//  AkuFocusDoctorCell.m
//  KMedicine
//
//  Created by 阿酷 on 16/7/6.
//  Copyright © 2016年 caomu. All rights reserved.
//

#import "AkuFocusDoctorCell.h"
#import "AkuFocusDoctorModel.h"

@interface AkuFocusDoctorCell ()

// 装载 的 view
@property (nonatomic, weak) UIView *emBarkView;

// 头像
@property (nonatomic, weak) UIImageView *iconImgView;

// 名字
@property (nonatomic, weak) UILabel *nameLabel;

// 职位
@property (nonatomic, weak) UILabel *positionLabel;

// 医院
@property (nonatomic, weak) UILabel *hospitalLabel;

// stackView
@property (nonatomic, weak) UIStackView *stackView;

@end


@implementation AkuFocusDoctorCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI {
    
    // 装载 的 view
    UIView *emBarkView = [[UIView alloc] init];
    
    self.emBarkView = emBarkView;
    
    emBarkView.backgroundColor = [UIColor whiteColor];
    
    //MARK: - 阴影效果 +=================================================================
    emBarkView.layer.shadowOpacity = 0.5;
    
    [self addSubview:emBarkView];
    
    // 头像
    UIImageView *iconImgView = [[UIImageView alloc] init];
    
    iconImgView.image = [UIImage imageNamed:@"illness_img_person.png"];
    
    self.iconImgView = iconImgView;
    
    [emBarkView addSubview:iconImgView];
    
    // 名字 label
    UILabel *nameLabel = [[UILabel alloc] init];
    
    self.nameLabel = nameLabel;
    
    [emBarkView addSubview:nameLabel];
    
    // 职位 label
    UILabel *positionLabel = [[UILabel alloc] init];
    
    self.positionLabel = positionLabel;
    
    positionLabel.textColor = [UIColor grayColor];
    positionLabel.font = [UIFont systemFontOfSize:15];
    
    [emBarkView addSubview:positionLabel];
    
    // 医院 label
    UILabel *hospitalLabel = [[UILabel alloc] init];
    
    self.hospitalLabel = hospitalLabel;
    
    hospitalLabel.textColor = [UIColor grayColor];
    hospitalLabel.font = [UIFont systemFontOfSize:15];
    
    [emBarkView addSubview:hospitalLabel];
    
    // stackView
    UIStackView *stackView = [[UIStackView alloc] init];
    
    self.stackView = stackView;
    
    stackView.backgroundColor = [UIColor redColor];
    
    stackView.distribution = UIStackViewDistributionFillEqually;
    
    [emBarkView addSubview:stackView];
    
    // 设置 锦旗 预约量 鲜花 button
    [stackView addArrangedSubview:[self setButtonWithImgStr:@"yuyueliang"]];
    [stackView addArrangedSubview:[self setButtonWithImgStr:@"xianhua"]];
    [stackView addArrangedSubview:[self setButtonWithImgStr:@"jinqi"]];
    
    
    
    [self setViewMasonry];
}


- (void)setViewMasonry {
    
    
    // 装载 view  的约束
    [self.emBarkView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.offset(UIEdgeInsetsMake(10, 10, 10, 10));
    }];
    
    // 头像
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.offset(10);
        make.bottom.offset(-10);
        make.width.equalTo(self.iconImgView.height);
    }];
    
    // 名字 label
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.offset(10);
        make.left.equalTo(self.iconImgView.mas_right).offset(10);
    }];

    // 医院 label
    [self.hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.nameLabel.mas_top);
        make.left.equalTo(self.nameLabel.mas_right).offset(10);
    }];
    
    // 职位 label
    [self.positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.nameLabel.mas_bottom).offset(4);
        make.left.equalTo(self.nameLabel.mas_left);
    }];
    
    // stackView
    [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.positionLabel.mas_bottom).offset(4);
        make.height.offset(16);
        make.left.equalTo(self.nameLabel.mas_left);
        make.width.offset(200);
    }];
    
    
    
}



- (void)setFocusDoctorCellmodel:(AkuFocusDoctorModel *)focusDoctorCellmodel {
    
    _focusDoctorCellmodel   = focusDoctorCellmodel;
    
    self.nameLabel.text     = focusDoctorCellmodel.name;
    self.positionLabel.text = focusDoctorCellmodel.position;
    self.hospitalLabel.text = focusDoctorCellmodel.hospital;
    
}

// 设置 button
- (UIButton *)setButtonWithImgStr:(NSString *)imgStr {
    
    UIButton *button1 = [[UIButton alloc] init];
    
    [button1 setTitle:[NSString stringWithFormat:@"%d", arc4random_uniform(100)] forState:UIControlStateNormal];
    
    button1.titleLabel.font = [UIFont systemFontOfSize:14];
    
    button1.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    [button1 setTitleColor:kThemeColor forState:UIControlStateNormal];
    [button1 setImage:[UIImage imageNamed:imgStr] forState:UIControlStateNormal];

    return button1;
    
}


@end

















